import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;


public class KeyController implements KeyListener{

	public static int[] keys = new int[255];
	public boolean UP, DOWN, ZERO;
	public boolean W, S, SPACE;
	
	int pOneDir = 0;
	int pTwoDir = 0;
	boolean pTwoFire, pOneFire;
	public KeyController(){
		for(int i = 0; i < 255; i++)
			keys[i] = 0;
	}

	
	public void keyPressed(KeyEvent k) {
		keys[k.getKeyCode()] = 1; 
		System.out.println("Key # "+k.getKeyCode());
		
		if(k.getKeyCode()== KeyEvent.VK_W){
			W = true;
		}else if(k.getKeyCode()== KeyEvent.VK_S){
			S = true;
		} else if(k.getKeyCode() == KeyEvent.VK_UP){
			UP = true;
		} else if(k.getKeyCode()== KeyEvent.VK_DOWN){
			DOWN = true;
		}else if(k.getKeyCode()== KeyEvent.VK_NUMPAD0){
			ZERO = true;
		}else if(k.getKeyCode()== KeyEvent.VK_SPACE){
			SPACE = true;
		}
		
		if(UP) pTwoDir = pTwoDir - 1;
		if(DOWN) pTwoDir = pTwoDir + 1;
		if(ZERO) pTwoFire = true;
		if(W) pOneDir = pOneDir -1;
		if(S) pOneDir = pOneDir +1;
		if(SPACE) pOneFire = true;
	}

	
	public void keyReleased(KeyEvent k) {
		keys[k.getKeyCode()] = 0;
		//if(UP){
			if(k.getKeyCode() == KeyEvent.VK_UP)
				UP = false;
			if(k.getKeyCode()== KeyEvent.VK_DOWN)
				DOWN = false;
			if(k.getKeyCode() == KeyEvent.VK_NUMPAD0)
				ZERO = false;
			if(k.getKeyCode()== KeyEvent.VK_W)
				W = false;
			if(k.getKeyCode()== KeyEvent.VK_S)
				S = false;
			if(k.getKeyCode()== KeyEvent.VK_SPACE)
				SPACE = false;
			
		//}
	}

	
	public void keyTyped(KeyEvent k) {
		
	}
	
	public int getPOneDir(){
		return pOneDir;
	}
	public int getPTwoDir(){
		return pTwoDir;
	}
	public boolean getP1Fire(){
		return pOneFire;
	}
	public boolean getP2Fire(){
		return pTwoFire;
	}

}
